<?php
namespace Home\Controller;
use Home\Controller\CommonController;
class ShopController extends CommonController {

    /**
      +----------------------------------------------------------
     * 首页
     *
      +----------------------------------------------------------
     */
    public function index() {
          

        
      
      $this->display();

    }





    

    public function detail(){
     $id=I('get.id');
     $shangpind=M('shangpin')->where(array("id"=>$id))->find();
      if (!empty($shangpind['jinz'])) {
        $map['id']  = array('in',$shangpind['jinz']);
         $ljj=M('huxing')->where($map)->select();
      }
      if (!empty($shangpind['yanse'])) {
    $map1['id'] = array('in',$shangpind['yanse']);
         
      $zlist=M('zlist')->where($map1)->select();
      }
        
     
        $result = M('shoucang')->where(array("userid"=>$_SESSION["userid"]))->find();
  
          $shangpin_shoucang = explode(',',$result['shangpin']);
  
     $this->assign("shangpin",$shangpin_shoucang);
      $this->assign('ljj',$ljj);
      $this->assign('zlist',$zlist);
      $this->assign('shangpind',$shangpind); 
      $this->display();
    }

 public function shangpin(){


   $fengge=I('post.fengge');
   $huxing=I('post.huxing');


   $fengge1=M('zlist')->where(array('id'=>$fengge))->find();

   $shangpin1=M('shangpin')->alias("a")->field("a.id,a.name,a.fengge,a.huxing,a.area,a.price,a.intro,a.img,a.userid,b.user as username")->join("zyb_user b on b.id = a.userid")->where(array('fengge'=>$fengge1['type_name']))->select();
  echo json_encode($shangpin1);




 }


  public function search(){

          $list=M('zlist')->select();
          
          $huxing=M('huxing')->order('id asc')->select();
          
          $fengge = I("get.fengge");
       $huxing1 = I("get.huxing");
       $where = "";

       if(!empty($fengge)){
          $data = M('zlist')->where("id = $fengge")->find();
          if(empty($where)){
            $where .= "a.fengge = '".$data['type_name']."'";
          }else{
            $where .= " and a.fengge = '".$data['type_name']."'";
          }
          
           
       }

       if(!empty($huxing1)){
          $data1 = M('huxing')->where("id=$huxing1")->find();
          if(empty($where)){
            $where .= "a.huxing = '".$data1['huxing']."'";
          }else{
            $where .= " and a.huxing = '".$data1['huxing']."'";
          }
       }
       
       $title=I('post.title');
         $map['a.name'] =array('like',"%$title%");
          $map['a.fengge'] =array('like',"%$title%");
          $map['a.huxing'] =array('like',"%$title%");
          $map['_logic'] = 'or';
    $shangpin=M('shangpin')->alias("a")->field("a.id,a.name,a.fengge,a.huxing,a.area,a.price,a.intro,a.img,a.userid,b.user as username")->join("zyb_user b on b.id = a.userid")->where($map)->order("a.id desc")->select();
         
            $this->assign("fengge",$fengge);
      $this->assign('list',$list);
      $this->assign('huxing',$huxing);
      $this->assign('huxing1',$huxing1);
            $this->assign('shangpin',$shangpin);
            $this->display();
        
    }  
    

}
 
?>